<?php

class Default_Service_Soap
{
    // define filters and validators for input
    private $_filters = array(
            'title' => array(
                    'HtmlEntities',
                    'StripTags',
                    'StringTrim'
            ),
            'shortdesc' => array(
                    'HtmlEntities',
                    'StripTags',
                    'StringTrim'
            ),
            'price' => array(
                    'HtmlEntities',
                    'StripTags',
                    'StringTrim'
            ),
            'quantity' => array(
                    'HtmlEntities',
                    'StripTags',
                    'StringTrim'
            )
    );

    private $_validators = array(
            'title' => array(),
            'shortdesc' => array(),
            'price' => array(
                    'Float'
            ),
            'quantity' => array(
                    'Int'
            )
    );

    /**
     * Returns list of all products in database
     *
     * @return array
     */
    public function getProducts ()
    {
        return array(
                "id" => 1,
                "getall" => 1
        );
    }

    /**
     * Returns specified product in database
     *
     * @param integer $id            
     * @return array Example_Exception
     */
    public function getProduct ($id)
    {
        return array(
                "id" => $id,
                "get" => 1
        );
    }

    /**
     * Adds new product to database
     *
     * @param array $data
     *            array of data values with keys -> table fields
     * @return integer id of inserted product
     */
    public function addProduct ($data)
    {
        $data['time'] = date("Y-m-d");
        return $data;
    }

    /**
     * Deletes product from database
     *
     * @param integer $id            
     * @return integer number of products deleted
     */
    public function deleteProduct ($id)
    {
        return array(
                "id" => $id,
                "delete" => "true"
        );
    }

    /**
     * Updates product in database
     *
     * @param integer $id            
     * @param array $data            
     * @return integer number of products updated
     */
    public function updateProduct ($id, $data)
    {
        return array(
                "id" => $id,
                "update" => "true",
                "data" => $data
        );
    }

    /**
     * Updates product in database
     *
     * @param array $data            
     * @return integer number of products updated
     */
    public function testProduct ($data)
    {   
        $data['xxxxxxxxxxxxxxxxxxxxxxxxxxxxxdxxxxxxxxxxxxxxxxxxxxxxxx'] =   $req = array(
                    'AsnCode' => 'RA0256120530010',
                    "AsnStatus" => 1,
                    'HeaderRequest' => array(
                            'customerId' => 'A0256',
                            'appToken' => 'asdffffffffffffffffffffffffasdfasdfasdfasdfasdfaffffffffffffffffffffffffffffffddddddddddddddddd',
                            'appKey' => 'ffdddfdfdeaadffffffffffffffasdf'
                    )
            );
        return $data;
    }

    /**
     * update pictures
     *
     * @param array $data            
     * @return array
     */
    public function uploadProduct ($data)
    {
        $result = array();
        foreach ($data['files'] as $k => $v)
        {
            $count = file_put_contents(
                    APPLICATION_PATH . "/../data/soapFiles/" . $v['fileName'], 
                    base64_decode($v['data']));
            
            $result[] = array(
                    $v['fileName'] => $count
            );
        }
        return $result;
    }
}